//
//  SeckillResultDetailViewController.m
//  CPICApp
//
//  Created by zhiwei li on 13-3-26.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "SeckillResultDetailViewController.h"
#import "RCAlertViewUtil.h"
#import "NSString+SBJson.h"
#import "Config.h"
#import "UIImageView+WebCache.h"
#import "DoorChargesViewController.h"
#import "AppDelegate.h"

@interface SeckillResultDetailViewController ()

@end

@implementation SeckillResultDetailViewController
@synthesize TableGoodsInfo;
@synthesize txtGoodsName;
@synthesize txtGoodsPrice;
@synthesize txtSmsIdentifyingInfo;
@synthesize Goodsname;
@synthesize GoodsPrice;
@synthesize SmsIdentifyingInfo;
@synthesize progress;
@synthesize OrderNo;
@synthesize OrderStatus;
@synthesize SeckillSuccessTime;
@synthesize txtOrderNo;
@synthesize txtOrderStatus;
@synthesize txtSeckillSuccessTime;
@synthesize OrderStatusName;
@synthesize SeckillResultdelegate;
@synthesize txtSerialNo;
@synthesize SerialNO;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
//        self.title = @"秒杀成功信息详情";
//        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *bgimage= [accountDefaults objectForKey:@"UserDefaultBgKindKey"];
    
    if ([bgimage isEqualToString:@"蓝色主题风格"]) 
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88@2x.png");
        ADD_LEFT_BUTTONITEM(@"back.png");
        ADD_TITLE_NAMEITEM(@"秒杀成功信息详情");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    else if([bgimage isEqualToString:@"棕色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88_01@2x.png");
        ADD_LEFT_BUTTONITEM(@"back_01.png");
        ADD_TITLE_NAMEITEM(@"秒杀成功信息详情");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773_01@2x"]];
    }
    else if([bgimage isEqualToString:@"重大节日皮肤"])
    {
        NSData *dataImg_02=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_02];
        NSLog(@"-------找到%@",dataImg_02);
        NSData *dataImg_03=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_03];
        NSData *dataImg_04=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_04];
        
        NSURL *urlSkinImg_02=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_02]];
        NSURL *urlSkinImg_03=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_03]];
        NSURL *urlSkinImg_04=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_04]];
        NSLog(@"-------找到333%@",urlSkinImg_02);
        
        UIImageView * LogoImage = [[UIImageView alloc]init];
        [LogoImage setImageWithURL:urlSkinImg_03 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(LogoImage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_03];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        LogoImage.image = [UIImage imageWithData:dataImg_03];
        LogoImage.frame = CGRectMake(0, 0, LogoImage.image.size.width/2, LogoImage.image.size.height/2);
        [self.view addSubview:LogoImage];
        
        //--------------------------
        UIButton * CallOutBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        CallOutBtn1.frame = CGRectMake(10, 10, 109/2, 57/2);
        UIImageView * Back = [[UIImageView alloc]init];
        [Back setImageWithURL:urlSkinImg_02 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(Back.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_02];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [Back setImage:[UIImage imageWithData:dataImg_02]];
        [CallOutBtn1 setImage:Back.image forState:UIControlStateNormal];
        [CallOutBtn1 addTarget:self action:@selector(ClickCallOutBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:CallOutBtn1];
        //--------------------------
        
        ADD_TITLE_NAMEITEM(@"秒杀成功信息详情");        
        
        UIImageView *bgimage = [[UIImageView alloc]initWithFrame:CGRectMake(0,44, self.view.frame.size.width, self.view.frame.size.height-44)];
        [bgimage setImageWithURL:urlSkinImg_04 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(bgimage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_04];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [bgimage setImage:[UIImage imageWithData:dataImg_04]];
        [self.view addSubview:bgimage];
        [bgimage release];
    }
    
    //定义产品信息列表
    TableGoodsInfo = [[UITableView alloc]initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, 300) style:UITableViewStyleGrouped];
    TableGoodsInfo.delegate = self;
    TableGoodsInfo.dataSource = self;
    TableGoodsInfo.backgroundView = nil;
    TableGoodsInfo.autoresizingMask = UIViewContentModeTop;
    TableGoodsInfo.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    TableGoodsInfo.scrollEnabled = NO;
    TableGoodsInfo.backgroundColor = [UIColor clearColor];
    [self.view addSubview:TableGoodsInfo];
    
    ArrGoodsInfoContent = [[NSMutableArray alloc]initWithObjects:@"道路救援服务", @"30.00",@"13800138000",nil];
    TableLine=0;
    
    [self setSeckillSuccessDetailRequest];
    
    DoorChargesBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [DoorChargesBtn setImage:[UIImage imageNamed:@"Submit_suggestion.png"] forState:UIControlStateNormal];
    [DoorChargesBtn setTitle:@"确认发货" forState:UIControlStateNormal];
    DoorChargesBtn.frame=CGRectMake(46, 378, 310/3, 119/2);
    [DoorChargesBtn addTarget:self action:@selector(subdoorcharges) forControlEvents:UIControlEventTouchUpInside];
    DoorChargesBtn.hidden=YES;
    [self.view addSubview:DoorChargesBtn];
    
    lbSuggestion = [[UILabel alloc]initWithFrame:CGRectMake(46, 366, 310/3, 119/2)];
    lbSuggestion.text = @"确认发货";
    lbSuggestion.textAlignment = UITextAlignmentCenter;
    lbSuggestion.textColor = [UIColor whiteColor];
    lbSuggestion.backgroundColor = [UIColor clearColor];
    lbSuggestion.hidden=YES;
    [self.view addSubview:lbSuggestion];
    [lbSuggestion release];
    
    CancelOrderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [CancelOrderBtn setImage:[UIImage imageNamed:@"Submit_suggestion.png"] forState:UIControlStateNormal];
    [CancelOrderBtn setTitle:@"取消订单" forState:UIControlStateNormal];
    CancelOrderBtn.frame=CGRectMake(186, 378, 310/3, 119/2);
    [CancelOrderBtn addTarget:self action:@selector(cancelorder) forControlEvents:UIControlEventTouchUpInside];
    CancelOrderBtn.hidden=YES;
    [self.view addSubview:CancelOrderBtn];
    
    lbCancelOrder = [[UILabel alloc]initWithFrame:CGRectMake(186, 366, 310/3, 119/2)];
    lbCancelOrder.text = @"取消订单";
    lbCancelOrder.textAlignment = UITextAlignmentCenter;
    lbCancelOrder.textColor = [UIColor whiteColor];
    lbCancelOrder.backgroundColor = [UIColor clearColor];
    lbCancelOrder.hidden=YES;
    [self.view addSubview:lbCancelOrder];
    [lbCancelOrder release];
    canSendMessage=YES;
    TimerInvalid=NO;
}

-(void) subdoorcharges
{
    DoorChargesViewController * doorcharges = [[DoorChargesViewController alloc]initView:self.Goodsname withgoodsprice:self.GoodsPrice withOrderid:self.SerialNO];
    [[AppDelegate app].unc pushViewController:doorcharges animated:YES];
    [doorcharges release];
}

-(void) cancelorder
{
    UIAlertView *myalert=[[UIAlertView alloc]initWithTitle:@"注意" message:@"你确定要取消订单吗!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    myalert.tag=2;
    [myalert show];
    [myalert release];
}

-(void) ClickCallOutBtn
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   //NSLog(@"我找到了-------%@",[ArrGoodsInfoContent count]);
    return TableLine;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        static NSString *Identifier=@"Identifier";
        UITableViewCell *cell=(UITableViewCell *)[TableGoodsInfo dequeueReusableCellWithIdentifier:Identifier];
        if (cell==nil)
        {
            cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            if (TableLine==7) {
                if(indexPath.row==0)
                {
                    UILabel *lblSerialnumber=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 116, 21)];
                    lblSerialnumber.backgroundColor=[UIColor clearColor];
                    lblSerialnumber.text=@"流水号";
                    lblSerialnumber.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:lblSerialnumber];
                    [lblSerialnumber release];
                    
                    txtSerialNo=[[UITextField alloc]initWithFrame:CGRectMake(65, 10.5, 248, 31)];
                    txtSerialNo.borderStyle=UITextBorderStyleNone;
                    txtSerialNo.returnKeyType=UIReturnKeyDone;
                    txtSerialNo.delegate=self;
                    txtSerialNo.enabled=NO;
                    txtSerialNo.font = [UIFont systemFontOfSize:14.0];
                    txtSerialNo.text=self.SerialNO;
                    [cell addSubview:txtSerialNo];
                    
                }
                else if(indexPath.row==1)
                {
                    UILabel *lblGoodsName=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 116, 21)];
                    lblGoodsName.backgroundColor=[UIColor clearColor];
                    lblGoodsName.text=@"订单号";
                    lblGoodsName.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:lblGoodsName];
                    [lblGoodsName release];
                    
                    txtOrderNo=[[UITextField alloc]initWithFrame:CGRectMake(65, 10.5, 248, 31)];
                    txtOrderNo.borderStyle=UITextBorderStyleNone;
                    txtOrderNo.returnKeyType=UIReturnKeyDone;
                    txtOrderNo.delegate=self;
                    txtOrderNo.font = [UIFont systemFontOfSize:14.0];
                    txtOrderNo.text=strordercode;
                    [cell addSubview:txtOrderNo];
                    [txtOrderNo setEnabled:NO];
                }
                else if(indexPath.row==2)
                {
                    UILabel *lblGoodsPrice=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 119, 21)];
                    lblGoodsPrice.backgroundColor=[UIColor clearColor];
                    lblGoodsPrice.text=@"订单状态";
                    lblGoodsPrice.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:lblGoodsPrice];
                    [lblGoodsPrice release];
                    
                    txtOrderStatus=[[UITextField alloc]initWithFrame:CGRectMake(85, 10.5, 148, 31)];
                    txtOrderStatus.borderStyle=UITextBorderStyleNone;
                    txtOrderStatus.returnKeyType=UIReturnKeyDone;
                    txtOrderStatus.delegate=self;
                    txtOrderStatus.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:txtOrderStatus];
                    txtOrderStatus.text = self.OrderStatusName;
                    [txtOrderStatus setEnabled:NO];
                }
                else if(indexPath.row==3)
                {
                    UILabel *lblSmsIdentifyingInfo=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 120, 21)];
                    lblSmsIdentifyingInfo.backgroundColor=[UIColor clearColor];
                    lblSmsIdentifyingInfo.text=@"秒杀成功时间";
                    lblSmsIdentifyingInfo.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:lblSmsIdentifyingInfo];
                    [lblSmsIdentifyingInfo release];
                    
                    txtSeckillSuccessTime=[[UITextField alloc]initWithFrame:CGRectMake(120, 10.5, 173, 31)];
                    txtSeckillSuccessTime.borderStyle=UITextBorderStyleNone;
                    txtSeckillSuccessTime.returnKeyType=UIReturnKeyDone;
                    txtSeckillSuccessTime.delegate =self;
                    txtSeckillSuccessTime.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:txtSeckillSuccessTime];
                    txtSeckillSuccessTime.text = self.SeckillSuccessTime;
                    [txtSeckillSuccessTime setEnabled:NO];
                }
                else if(indexPath.row==4)
                {
                    UILabel *lblGoodsName=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 116, 21)];
                    lblGoodsName.backgroundColor=[UIColor clearColor];
                    lblGoodsName.text=@"产品名称";
                    lblGoodsName.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:lblGoodsName];
                    [lblGoodsName release];
                    
                    txtGoodsName=[[UITextField alloc]initWithFrame:CGRectMake(85, 10.5, 148, 31)];
                    txtGoodsName.borderStyle=UITextBorderStyleNone;
                    txtGoodsName.returnKeyType=UIReturnKeyDone;
                    txtGoodsName.delegate=self;
                    txtGoodsName.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:txtGoodsName];
                    txtGoodsName.text = self.Goodsname;
                    [txtGoodsName setEnabled:NO];
                }
                else if(indexPath.row==5)
                {
                    UILabel *lblGoodsPrice=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 119, 21)];
                    lblGoodsPrice.backgroundColor=[UIColor clearColor];
                    lblGoodsPrice.text=@"产品价格";
                    lblGoodsPrice.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:lblGoodsPrice];
                    [lblGoodsPrice release];
                    
                    txtGoodsPrice=[[UITextField alloc]initWithFrame:CGRectMake(85, 10.5, 148, 31)];
                    txtGoodsPrice.borderStyle=UITextBorderStyleNone;
                    txtGoodsPrice.returnKeyType=UIReturnKeyDone;
                    txtGoodsPrice.delegate=self;
                    txtGoodsPrice.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:txtGoodsPrice];
                    txtGoodsPrice.text = self.GoodsPrice;
                    [txtGoodsPrice setEnabled:NO];
                }
                else if(indexPath.row==6)
                {
                    UILabel *lblSmsIdentifyingInfo=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 80, 21)];
                    lblSmsIdentifyingInfo.backgroundColor=[UIColor clearColor];
                    lblSmsIdentifyingInfo.text=@"补发短信";
                    lblSmsIdentifyingInfo.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:lblSmsIdentifyingInfo];
                    [lblSmsIdentifyingInfo release];
                    
                    txtSmsIdentifyingInfo=[[UITextField alloc]initWithFrame:CGRectMake(90, 7, 150, 31)];
                    txtSmsIdentifyingInfo.borderStyle=UITextBorderStyleLine;
                    txtSmsIdentifyingInfo.returnKeyType=UIReturnKeyDone;
                    CustomNumbleKeyboardView *customKeyboardView = [[CustomNumbleKeyboardView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 238)];
                    customKeyboardView.delegate = self;
                    [txtSmsIdentifyingInfo setInputView:customKeyboardView];
                    
                    txtSmsIdentifyingInfo.delegate =self;
                    txtSmsIdentifyingInfo.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:txtSmsIdentifyingInfo];
                    NSDictionary * DictCustomerInfo =[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_CUSTOMER_INFO];
                    if ([DictCustomerInfo valueForKey:@"phone"]) {
                        txtSmsIdentifyingInfo.text = [DictCustomerInfo valueForKey:@"phone"];
                    }
                    [txtSmsIdentifyingInfo setEnabled:YES];
                    
                    Reissuebtn = [UIButton buttonWithType:UIButtonTypeCustom];
                    Reissuebtn.frame = CGRectMake(245, 4.5, 110/2, 58/2);
                    [Reissuebtn setImage:[UIImage imageNamed:@"SecKill_05.png"] forState:UIControlStateNormal];
                    [Reissuebtn setTitle:@"补发" forState:(UIControlStateNormal)];
                    [Reissuebtn addTarget:self action:@selector(ReissueSms) forControlEvents:UIControlEventTouchUpInside];
                    [cell addSubview:Reissuebtn];
                }

            }
            else if(TableLine==5)
            {
                if(indexPath.row==0)
                {
                    UILabel *lblSerialnumber=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 116, 21)];
                    lblSerialnumber.backgroundColor=[UIColor clearColor];
                    lblSerialnumber.text=@"流水号";
                    lblSerialnumber.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:lblSerialnumber];
                    [lblSerialnumber release];
                    
                    txtSerialNo=[[UITextField alloc]initWithFrame:CGRectMake(65, 10.5, 248, 31)];
                    txtSerialNo.borderStyle=UITextBorderStyleNone;
                    txtSerialNo.returnKeyType=UIReturnKeyDone;
                    txtSerialNo.delegate=self;
                    txtSerialNo.enabled=NO;
                    txtSerialNo.font = [UIFont systemFontOfSize:14.0];
                    txtSerialNo.text=self.SerialNO;
                    [cell addSubview:txtSerialNo];
                    
                }
                else if(indexPath.row==1)
                {
                    UILabel *lblGoodsPrice=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 119, 21)];
                    lblGoodsPrice.backgroundColor=[UIColor clearColor];
                    lblGoodsPrice.text=@"订单状态";
                    lblGoodsPrice.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:lblGoodsPrice];
                    [lblGoodsPrice release];
                    
                    txtOrderStatus=[[UITextField alloc]initWithFrame:CGRectMake(85, 10.5, 148, 31)];
                    txtOrderStatus.borderStyle=UITextBorderStyleNone;
                    txtOrderStatus.returnKeyType=UIReturnKeyDone;
                    txtOrderStatus.delegate=self;
                    txtOrderStatus.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:txtOrderStatus];
                    txtOrderStatus.text = self.OrderStatusName;
                    [txtOrderStatus setEnabled:NO];
                }
                else if(indexPath.row==2)
                {
                    UILabel *lblSmsIdentifyingInfo=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 120, 21)];
                    lblSmsIdentifyingInfo.backgroundColor=[UIColor clearColor];
                    lblSmsIdentifyingInfo.text=@"秒杀成功时间";
                    lblSmsIdentifyingInfo.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:lblSmsIdentifyingInfo];
                    [lblSmsIdentifyingInfo release];
                    
                    txtSeckillSuccessTime=[[UITextField alloc]initWithFrame:CGRectMake(120, 10.5, 173, 31)];
                    txtSeckillSuccessTime.borderStyle=UITextBorderStyleNone;
                    txtSeckillSuccessTime.returnKeyType=UIReturnKeyDone;
                    txtSeckillSuccessTime.delegate =self;
                    txtSeckillSuccessTime.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:txtSeckillSuccessTime];
                    txtSeckillSuccessTime.text = self.SeckillSuccessTime;
                    [txtSeckillSuccessTime setEnabled:NO];
                }
                else if(indexPath.row==3)
                {
                    UILabel *lblGoodsName=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 116, 21)];
                    lblGoodsName.backgroundColor=[UIColor clearColor];
                    lblGoodsName.text=@"产品名称";
                    lblGoodsName.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:lblGoodsName];
                    [lblGoodsName release];
                    
                    txtGoodsName=[[UITextField alloc]initWithFrame:CGRectMake(85, 10.5, 148, 31)];
                    txtGoodsName.borderStyle=UITextBorderStyleNone;
                    txtGoodsName.returnKeyType=UIReturnKeyDone;
                    txtGoodsName.delegate=self;
                    txtGoodsName.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:txtGoodsName];
                    txtGoodsName.text = self.Goodsname;
                    [txtGoodsName setEnabled:NO];
                }
                else if(indexPath.row==4)
                {
                    UILabel *lblGoodsPrice=[[UILabel alloc]initWithFrame:CGRectMake(15, 9.5, 119, 21)];
                    lblGoodsPrice.backgroundColor=[UIColor clearColor];
                    lblGoodsPrice.text=@"产品价格";
                    lblGoodsPrice.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:lblGoodsPrice];
                    [lblGoodsPrice release];
                    
                    txtGoodsPrice=[[UITextField alloc]initWithFrame:CGRectMake(85, 10.5, 148, 31)];
                    txtGoodsPrice.borderStyle=UITextBorderStyleNone;
                    txtGoodsPrice.returnKeyType=UIReturnKeyDone;
                    txtGoodsPrice.delegate=self;
                    txtGoodsPrice.font = [UIFont systemFontOfSize:14.0];
                    [cell addSubview:txtGoodsPrice];
                    txtGoodsPrice.text = self.GoodsPrice;
                    [txtGoodsPrice setEnabled:NO];
                }

            }
    
            
    
        }

        return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

//数字键盘
- (void)numberKeyBoardInput:(NSInteger) number
{
    NSMutableString *textString = [[[NSMutableString alloc] initWithFormat:@"%@%d",txtSmsIdentifyingInfo.text,number] autorelease];
    if ([textString length]>11)
    {
        [self justShowMessage:@"手机号码输入不能超过11位!" title:@""];
        return;
    }
    txtSmsIdentifyingInfo.text = textString;
}

- (void)numberKeyBoardBackspace
{
    NSMutableString* mutableString = [[[NSMutableString alloc] initWithFormat:@"%@", txtSmsIdentifyingInfo.text] autorelease];
    if ([mutableString length] >=1) {
        NSRange tmpRange;
        tmpRange.location = [mutableString length] - 1;
        tmpRange.length = 1;
        [mutableString deleteCharactersInRange:tmpRange];
    }
    txtSmsIdentifyingInfo.text = mutableString;
    
}

- (void)numberKeyBoardFinish
{
    [txtSmsIdentifyingInfo resignFirstResponder];
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if(textField==txtSmsIdentifyingInfo)
    {
        [self SetAnimation:120];
    }
    
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if(textField==txtSmsIdentifyingInfo)
    {
        [self backAnimation:120];
    }
}

-(void)SetAnimation:(CGFloat)Xorigin
{
    NSTimeInterval animationDuration = 0.30f;
    CGRect frame = self.view.frame;
    //frame.origin.x+=Xorigin;
    frame.origin.y-=Xorigin;
    //frame.size.height +=Xorigin;
    self.view.frame = frame;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame = frame;
    [UIView commitAnimations];
}

-(void)backAnimation:(CGFloat)Xorigin
{
    NSTimeInterval animationDuration = 0.30f;
    CGRect frame = self.view.frame;
    //frame.origin.x -=Xorigin;
    frame.origin.y+=Xorigin;
    //frame.size.height -=Xorigin;
    self.view.frame = frame;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame = frame;
    [UIView commitAnimations];
    // [textField resignFirstResponder];
}



-(id)initView:(NSString *)SecKillCommodityID withorderID:(NSString *)orderID withSerialNO:(NSString *)serialNO
{
    SecKillcommodityId = SecKillCommodityID;
    self.OrderNo = orderID;
    self.SerialNO=serialNO;
    self = [super init];
    return self;
}

//响应补发操作
-(void) ReissueSms
{


    if (canSendMessage==YES) {
        if (txtSmsIdentifyingInfo.text.length == 0)
        {
            [self justShowMessage:@"接收短信手机号码不能为空!" title:@"提示"];
            return;
        }
        
        NSString * Mobile = txtSmsIdentifyingInfo.text;
        if (![self isValidateMobile:Mobile])
        {
            [self justShowMessage:@"非法的手机号码,请输入正确的手机号码" title:@""];
            return;
        }
        canSendMessage=NO;
        myTimer=[NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(scrollTimer) userInfo:nil repeats:NO];
        [self setSendSmsRequest];
    }
    else
    {
        [self justShowMessage:@"您不能频繁发送，1分钟之后方可再发" title:@"注意"];
    }

}

-(void)scrollTimer
{
    canSendMessage=YES;
}
-(void)setSeckillSuccessDetailRequest//向太保移动平台发送秒杀成功详细信息请求报文
{
    NSLog(@"userinfodefault%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_USER_INFO]);
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) {
        if ([dictUserInfo valueForKey:@"UserAccount"]) {
            NSLog(@"%@",[dictUserInfo valueForKey:@"UserAccount"]);
        }
    }
    else
    {
//        [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
//        return;
    }

    NSString * useraccount;
    if ([dictUserInfo valueForKey:@"UserAccount"]) {
        useraccount = [dictUserInfo valueForKey:@"UserAccount"];
    }
    else
    {
        useraccount=@"cpic";
    }
//    NSString *StrRequestCode=@"RequestCode=50405";
    NSString *StrRequestData=[NSString stringWithFormat:@"{\"orderID\":\"%@\",\"SecKillCommodityID\":\"%@\",\"UserAccount\":\"%@\"}",self.SerialNO,SecKillcommodityId,useraccount];
//    NSString *strUrl=[NSString stringWithFormat:@"%@%@%@",Server_Url,StrRequestCode,StrRequestData];
//    NSLog(@"++++++++++++++%@",strUrl);
//    NSString *StrUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
//    
//    NSLog(@"22222222222222%@",StrUrl);
//    
//    NSURL *Myurl = [NSURL URLWithString:StrUrl];//This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
//    NSLog(@"URL:%@",Myurl);
    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [request setPostValue:@"50405" forKey:@"RequestCode"];
    [request setPostValue:StrRequestData forKey:@"RequestData"];
    
    [request setDelegate:self];
    [request setDidFailSelector:@selector(ResponseFail:)];
    [request setDidFinishSelector:@selector(ResonseSuccess:)];
    [request startAsynchronous];
    
    showProgress = YES;
    if (showProgress)
    {
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"加载中...";
        [progress show:YES];
        showProgress = NO;
    }
}

- (void)ResonseSuccess:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSString *responseString = [request responseString];
    NSLog(@"responseString====%@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse======%@",dictResponse);
    NSMutableDictionary *jsonoSubObj = [dictResponse objectForKey:@"head"];
    NSString * ss = [[NSString alloc] initWithFormat:@"%@",[jsonoSubObj objectForKey:@"success"]];
    if ([ss isEqualToString:@"1"])
    {
        self.Goodsname=[dictResponse valueForKey:@"secKillCommodityName"];
        self.GoodsPrice=[[NSString alloc] initWithFormat:@"%@",[dictResponse valueForKey:@"secKillCommodityPrice"]];
        
        self.OrderStatusName = [dictResponse valueForKey:@"orderstatusname"];
        self.SeckillSuccessTime = [dictResponse valueForKey:@"successSecKillTime"];
        self.OrderStatus = [dictResponse valueForKey:@"orderstatus"];
        if ([dictResponse valueForKey:@"ordercode"]) {
            strordercode=[[NSString alloc]initWithFormat:@"%@",[dictResponse valueForKey:@"ordercode"]];
            self.txtOrderNo.text=strordercode;

        }
        NSLog(@"=============%@",self.OrderNo);
        NSLog(@"=============%@",self.OrderStatusName);
        NSLog(@"=============%@",self.SeckillSuccessTime);
        
        txtSmsIdentifyingInfo.text=@"";
        txtGoodsName.text = self.Goodsname;
        txtGoodsPrice.text = self.GoodsPrice;
        //txtOrderNo.text = self.OrderNo;
        txtOrderStatus.text = self.OrderStatusName;
        txtSeckillSuccessTime.text = self.SeckillSuccessTime;
        //[self justShowMessage:@"秒杀成功详细信息查询成功！" title:@"提示"];
        
        if ([self.OrderStatus isEqualToString:@"SKOS_00"])
        {
            [CancelOrderBtn setHidden:NO];
            [lbCancelOrder setHidden:NO];
            [DoorChargesBtn setHidden:NO];
            [lbSuggestion setHidden:NO];
        }
        else 
        {
            [CancelOrderBtn setHidden:YES];
            [lbCancelOrder setHidden:YES];
            [DoorChargesBtn setHidden:YES];
            [lbSuggestion setHidden:YES];
        }
        
        if ([self.OrderStatus isEqualToString:@"SKOS_00"] || [self.OrderStatus isEqualToString:@"SKOS_40"])
        {
            TableLine=5;
            Reissuebtn.hidden=YES;
            [TableGoodsInfo reloadData];
        }
        else
        {
            TableLine=7;
            Reissuebtn.hidden=NO;
            [TableGoodsInfo reloadData];
        }

    }
    else
    {
        [self justShowMessage:@"秒杀成功详细信息查询失败！" title:@"提示"];
    }
}

- (void)ResponseFail:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败！" title:@"提示"];
}


-(void)setSendSmsRequest///向太保移动平台发送补发短信请求报文
{
    NSLog(@"userinfodefault%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_USER_INFO]);
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) {
        if ([dictUserInfo valueForKey:@"UserAccount"]) {
            NSLog(@"%@",[dictUserInfo valueForKey:@"UserAccount"]);
        }
    }
    else
    {
//        [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
//        return;
    }
    
    NSString * useraccount;
    if ([dictUserInfo valueForKey:@"UserAccount"]) {
        useraccount = [dictUserInfo valueForKey:@"UserAccount"];
    }
    else
    {
        useraccount=@"cpic";
    }
//    NSString *StrRequestCode=@"RequestCode=62301";
    NSString *StrRequestData=[NSString stringWithFormat:@"{\"phoneNo\":\"%@\",\"UserAccount\":\"%@\",\"commodityName\":\"%@\",\"commodityId\":\"%@\"}",txtSmsIdentifyingInfo.text,useraccount,txtOrderNo.text,txtGoodsName.text];
//    NSString *strUrl=[NSString stringWithFormat:@"%@%@%@",Server_Url,StrRequestCode,StrRequestData];
//    NSLog(@"++++++++++++++%@",strUrl);
//    NSString *StrUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
//    
//    NSLog(@"22222222222222%@",StrUrl);
//    
//    NSURL *Myurl = [NSURL URLWithString:StrUrl];//This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
//    NSLog(@"URL:%@",Myurl);
    ASIFormDataRequest *requestone = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [requestone setPostValue:@"62301" forKey:@"RequestCode"];
    [requestone setPostValue:StrRequestData forKey:@"RequestData"];
    
    [requestone setDelegate:self];
    [requestone setDidFailSelector:@selector(ResponseFailone:)];
    [requestone setDidFinishSelector:@selector(ResonseSuccessone:)];
    [requestone startAsynchronous];
    
    showProgress = YES;
    if (showProgress)
    {
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"加载中...";
        [progress show:YES];
        showProgress = NO;
    }
}

- (void)ResonseSuccessone:(ASIHTTPRequest *)requestone
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSString *responseString = [requestone responseString];
    NSLog(@"responseString====%@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse======%@",dictResponse);
    NSMutableDictionary *jsonoSubObj = [dictResponse objectForKey:@"head"];
    NSString * ss = [[NSString alloc] initWithFormat:@"%@",[jsonoSubObj objectForKey:@"success"]];
    if ([ss isEqualToString:@"1"])
    {
        [self justShowMessage:@"补发短信成功！" title:@"提示"];
    }
    else
    {
        [self justShowMessage:@"补发短信失败！" title:@"提示"];
    }
}

- (void)ResponseFailone:(ASIHTTPRequest *)requestone
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败！" title:@"提示"];
}

-(void)setCancelOrderRequest///向太保移动平台发送取消订单请求报文
{
    NSLog(@"userinfodefault%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_USER_INFO]);
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) {
        if ([dictUserInfo valueForKey:@"UserAccount"]) {
            NSLog(@"%@",[dictUserInfo valueForKey:@"UserAccount"]);
        }
    }
    else
    {
//        [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
//        return;
    }
    
    NSString * useraccount;
    if ([dictUserInfo valueForKey:@"UserAccount"]) {
        useraccount = [dictUserInfo valueForKey:@"UserAccount"];
    }
    else
    {
        useraccount=@"cpic";
    }
//    NSString *StrRequestCode=@"RequestCode=50407";
    NSString *StrRequestData=[NSString stringWithFormat:@"{\"orderID\":\"%@\",\"UserAccount\":\"%@\"}",txtSerialNo.text,useraccount];
//    NSString *strUrl=[NSString stringWithFormat:@"%@%@%@",Server_Url,StrRequestCode,StrRequestData];
//    NSLog(@"++++++++++++++%@",strUrl);
//    NSString *StrUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
//    
//    NSLog(@"22222222222222%@",StrUrl);
//    
//    NSURL *Myurl = [NSURL URLWithString:StrUrl];//This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
//    NSLog(@"URL:%@",Myurl);
    ASIFormDataRequest *requesttwo = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [requesttwo setPostValue:@"50407" forKey:@"RequestCode"];
    [requesttwo setPostValue:StrRequestData forKey:@"RequestData"];
    
    [requesttwo setDelegate:self];
    [requesttwo setDidFailSelector:@selector(ResponseFailtwo:)];
    [requesttwo setDidFinishSelector:@selector(ResonseSuccesstwo:)];
    [requesttwo startAsynchronous];
    
    showProgress = YES;
    if (showProgress)
    {
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"加载中...";
        [progress show:YES];
        showProgress = NO;
    }
}

- (void)ResonseSuccesstwo:(ASIHTTPRequest *)requesttwo
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSString *responseString = [requesttwo responseString];
    NSLog(@"responseString====%@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse======%@",dictResponse);
    NSMutableDictionary *jsonoSubObj = [dictResponse objectForKey:@"head"];
    NSString * ss = [[NSString alloc] initWithFormat:@"%@",[jsonoSubObj objectForKey:@"success"]];
    if ([ss isEqualToString:@"1"])
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                                       message:@"取消订单成功！"
                                                      delegate:nil
                                             cancelButtonTitle:@"确定"
                                             otherButtonTitles:nil];
        [alert setTag:1];
        [alert show];
        alert.delegate=self;
        [alert release];
    }
    else
    {
        [self justShowMessage:@"取消订单失败！" title:@"提示"];
    }
}

- (void)ResponseFailtwo:(ASIHTTPRequest *)requesttwo
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败！" title:@"提示"];
}

#pragma mark-- UIAlertViewDelegate
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag==1)
    {
        if ([SeckillResultdelegate respondsToSelector:@selector(RefreshSeckillResultQueryRequest)]) {
            [SeckillResultdelegate RefreshSeckillResultQueryRequest];
        }
        if (buttonIndex==0) 
        {
            [[AppDelegate app].unc popViewControllerAnimated:YES];
        }
        else
        {
            [[AppDelegate app].unc popViewControllerAnimated:YES];
        }
    }
    else if(alertView.tag==2)
    {
        if (buttonIndex==0) {
            ;
        }
        else if(buttonIndex==1)
        {
            [self setCancelOrderRequest];
        }
    }
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if(textField==txtSmsIdentifyingInfo)
    {
        if(range.location>=11)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    return YES;
}

/*手机号码验证*/
-(BOOL) isValidateMobile:(NSString *)mobile
{
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    [progress release];
    [TableGoodsInfo release];
    [Goodsname release];
    [GoodsPrice release];
    [SmsIdentifyingInfo release];
    [SeckillSuccessTime release];
    [OrderNo release];
    [OrderStatus release];
    [txtOrderStatus release];
    [txtOrderNo release];
    [txtSeckillSuccessTime release];
    [OrderStatusName release];
    [txtGoodsName release];
    [SerialNO release];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
